//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "KernelInterpolation2D.h"
using namespace Cephei::QL::Math::Interpolations;
#include <gen/QL/Math/Matrix.h>
#include <gen/QL/Math/Interpolations/Interpolation2D.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Interpolations::CKernelInterpolation2D::CKernelInterpolation2D (boost::shared_ptr<QuantLib::KernelInterpolation2D>& childNative, Object^ owner) : CInterpolation2D(CKernelInterpolation2D::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation2D = NULL;
#endif
	_ppKernelInterpolation2D = &childNative;
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppKernelInterpolation2D));
}
Cephei::QL::Math::Interpolations::CKernelInterpolation2D::CKernelInterpolation2D (QuantLib::KernelInterpolation2D& childNative, Object^ owner) : CInterpolation2D(CKernelInterpolation2D::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation2D = NULL;
#endif
	_ppKernelInterpolation2D = new boost::shared_ptr<QuantLib::KernelInterpolation2D> (&childNative);
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppKernelInterpolation2D));
    _KernelInterpolation2DOwner = owner;
    _Interpolation2DOwner = owner;
}

Cephei::QL::Math::Interpolations::CKernelInterpolation2D::CKernelInterpolation2D (CKernelInterpolation2D^ copy) : CInterpolation2D(CKernelInterpolation2D::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation2D = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppKernelInterpolation2D = new boost::shared_ptr<QuantLib::KernelInterpolation2D> (copy->GetShared());
        _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppKernelInterpolation2D));
    }
}
Cephei::QL::Math::Interpolations::CKernelInterpolation2D::CKernelInterpolation2D (System::Type^ t) : CInterpolation2D(CKernelInterpolation2D::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation2D = NULL;
#endif
	if (!t->IsSubclassOf(CKernelInterpolation2D::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Interpolations::CKernelInterpolation2D::CKernelInterpolation2D (QuantLib::Handle<QuantLib::KernelInterpolation2D>& childNative, Object^ owner)  : CInterpolation2D(CKernelInterpolation2D::typeid)
{
	_phKernelInterpolation2D = &childNative;
	_ppKernelInterpolation2D = &static_cast<boost::shared_ptr<QuantLib::KernelInterpolation2D>>(childNative.currentLink());
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppKernelInterpolation2D));
    _KernelInterpolation2DOwner = owner;
}
Cephei::QL::Math::Interpolations::CKernelInterpolation2D::CKernelInterpolation2D (QuantLib::Handle<QuantLib::KernelInterpolation2D> childNative)  : CInterpolation2D(CKernelInterpolation2D::typeid)
{
	_phKernelInterpolation2D = &childNative;
	_ppKernelInterpolation2D = &static_cast<boost::shared_ptr<QuantLib::KernelInterpolation2D>>(childNative.currentLink());
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppKernelInterpolation2D));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Interpolations::CKernelInterpolation2D::CKernelInterpolation2D (QuantLib::KernelInterpolation2D childNative)  : CInterpolation2D(CKernelInterpolation2D::typeid)
{
#ifdef HANDLE
	_phKernelInterpolation2D = NULL;
#endif
	_ppKernelInterpolation2D = new boost::shared_ptr<QuantLib::KernelInterpolation2D> (new QuantLib::KernelInterpolation2D (childNative));
    _ppInterpolation2D = new boost::shared_ptr<QuantLib::Interpolation2D> (boost::dynamic_pointer_cast<QuantLib::Interpolation2D> (*_ppKernelInterpolation2D));
}
#endif

Cephei::QL::Math::Interpolations::CKernelInterpolation2D::~CKernelInterpolation2D ()
{
    if (_ppKernelInterpolation2D != NULL)
    {
	    delete _ppKernelInterpolation2D;
        _ppKernelInterpolation2D = NULL;
    }
}
Cephei::QL::Math::Interpolations::CKernelInterpolation2D::!CKernelInterpolation2D ()
{
    if (_ppKernelInterpolation2D != NULL)
    {
	    delete _ppKernelInterpolation2D;
    }
}
QuantLib::KernelInterpolation2D& Cephei::QL::Math::Interpolations::CKernelInterpolation2D::GetReference ()
{
    if (_ppKernelInterpolation2D == NULL) throw gcnew NativeNullException ();
	return **_ppKernelInterpolation2D;
}
boost::shared_ptr<QuantLib::KernelInterpolation2D>& Cephei::QL::Math::Interpolations::CKernelInterpolation2D::GetShared ()
{
    if (_ppKernelInterpolation2D == NULL) throw gcnew NativeNullException ();
	return *_ppKernelInterpolation2D;
}
QuantLib::KernelInterpolation2D* Cephei::QL::Math::Interpolations::CKernelInterpolation2D::GetPointer ()
{
    if (_ppKernelInterpolation2D == NULL) throw gcnew NativeNullException ();
	return &**_ppKernelInterpolation2D;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::KernelInterpolation2D>& Cephei::QL::Math::Interpolations::CKernelInterpolation2D::GetHandle ()
{
	if (_phKernelInterpolation2D == NULL)
	{
		_phKernelInterpolation2D = new Handle<QuantLib::KernelInterpolation2D> (*_ppKernelInterpolation2D);
	}
	return *_phKernelInterpolation2D;
}
#endif
bool Cephei::QL::Math::Interpolations::CKernelInterpolation2D::HasNative () 
{
	return (_ppKernelInterpolation2D != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

